import json

STORAGE_PATH = './storage'
LOG_PATH = './log'

BASE_URL = "https://api2.dokkr.net/"
AUTH_URL = "https://mc2-h5.dokkr.net/auth.html#/?type=5&secretCode="
REQUEST_PARAMS = {"version": "1.8.6", "pid": "5", "lang": "chs"}

data = None

def path(name):
    return f'{STORAGE_PATH}/{name}.json'

def get(name):
    with open(path(name), "r") as file:
            return json.load(file)

def set(name, data):
    with open(path(name), "w") as file:
        json.dump(data, file)

def load():
    global data
    if data is None:
        data = get('config')

def write(name, value):
    global data
    load()
    data[name] = value
    set('config', data)

def read(name):
    global data
    load()
    return data.get(name, None)